

package com.hazelcast.function;

import com.hazelcast.internal.util.ExceptionUtil;

import java.util.function.BiFunction;

/**
 * A {@link BiFunction} that declares checked exception.
 *
 * @param <T> the type of the first argument to the function
 * @param <U> the type of the second argument to the function
 * @param <R> the type of the result of the function
 * @since 6.0
 */
@FunctionalInterface
public interface ThrowingBiFunction<T, U, R> extends BiFunction<T, U, R> {

    /**
     * Apply given items.
     *
     * @see BiFunction#apply(Object, Object)
     */
    R applyEx(T t, U u) throws Exception;

    @Override
    default R apply(T t, U u) {
        try {
            return applyEx(t, u);
        } catch (Exception e) {
            throw ExceptionUtil.sneakyThrow(e);
        }
    }
}
